class Solution {
public:
    int tribonacci(int n) {
        int n0 = 0, n1 = 1, n2 = 1;
        if (n == 0)
            return 0;
        else if (n <= 2)
            return 1;
        int sum;
        for (int i = 3; i <= n; i++)
        {
            sum = n0 + n1 + n2;
            n0 = n1;
            n1 = n2;
            n2 = sum;
        }
        return sum;
    }
};